package com.itheima.health.controller;

import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.service.MenuService;
import com.itheima.health.vo.MenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "菜单管理")
public class MenuController {
    @Reference
    private MenuService menuService;

    @PostMapping("menu/findByPage")
    @ApiOperation(value = "分页查找",notes = "分页查找")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
       return new Result(menuService.findPage(queryPageBean));
    }

    @GetMapping("menu/findAll")
    @ApiOperation(value = "查询所有",notes = "查询权限列表信息")
    public Result findAll(){
        //    分页查询  条件  页码  记录数  条件
        //  集合 插件  PageResult对象
        return new Result(menuService.list());
    }


    @PostMapping("menu/saveOrUpdate")
    @ApiOperation(value = "添加修改菜单",notes = "添加修改菜单")
    public Result saveOrUpdate(@RequestBody MenuVO menuVO){
        return new Result(menuService.saveOrUpdateMenu(menuVO));
    }


    @DeleteMapping("menu/deleteById/{id}")
    @ApiOperation(value = "添加菜单",notes = "添加菜单")
    public Result deleteById(@PathVariable("id") Integer id ){
        return new Result(menuService.removeById(id));
    }

}
